import styles from './index.module.scss';
import Icon from '@/components/Icon';
import { ReactNode } from 'react';
import { useHistory } from 'react-router-dom';
import classNames from 'classnames';
type NavBarType = {
  onBack?: () => void;
  children?: ReactNode;
  right?: ReactNode;
  //
  fixed?: boolean;
};
export default function NavBar({ onBack, children, right, fixed }: NavBarType) {
  const history = useHistory();
  const onhandleFn = () => {
    if (onBack) {
      return onBack();
    }
    history.go(-1);
  };
  return (
    <div className={styles.root}>
      <div className={classNames('main', { fixed: fixed })}>
        {/* 后退按钮 */}
        <div className="left">
          {/* <Icon type="iconfanhui" onClick={onBack} /> */}
          <Icon type="iconfanhui" onClick={onhandleFn} />
        </div>
        {/* 居中标题 */}
        <div className="title">{children}</div>
        {/* 右侧内容 */}
        <div className="right">{right}</div>
      </div>

      {/* 记得解构过来 */}
    </div>
  );
}
